/**
  * Author: Mei
  * Date: 2020-12-30 19:13
  * Description: 通过索引来展开并打印tuple
  *
  *
  */
#include "../head.h"

template<int... a>
struct IndexTuple { //得到所有的索引
    print() {
        cout << sizeof...(a);
    }
};

template<int N, int ... Indexes>
struct MakeIndexes : MakeIndexes<N - 1, N - 1, Indexes...> {
};

template<int ...indexes>
struct MakeIndexes<0, indexes...> {
    typedef IndexTuple<indexes...> type; //保存一包数据
};

template<typename T>
void Print(T t) {
    cout << t << " ";
}

template<typename T, typename ... Args>
void Print(T t, Args ... args) {
    //cout << "size: "<< sizeof...(args) << endl;
    cout << t << " ";
    Print(args...);
};

template<typename Tuple, int ... Indexes>
void Transform(IndexTuple<Indexes...> &&in, Tuple &tp) {  //根据索引取值
    Print(get<Indexes>(tp)...); //应该把值通过get取出来了
};
template<int...>
struct IndexTp {
};

template<typename Tuple, typename ... Indexes>
//void Transform2(IndexTp<Indexes...>, Tuple &tp) {  //根据索引取值
void Transform2(Tuple &tp, Indexes ... indexes) {  //根据索引取值
    Print(indexes...); //应该把值通过get取出来了
};

//另一种方式
template<typename T>
void Fun(T t) {
    cout << t << " ";
};

template<typename Tuple, int ... Indexes>
void Transform1(IndexTuple<Indexes...> &&in, Tuple &tp) {  //根据索引取值
    int a[] = {(Fun(get<Indexes>(tp)), 0)...};
};

int main() {
    using Tuple = tuple<int, short, double, char, bitset<8>>;
    Tuple tp = make_tuple(1, 2, 3, 'a', 10);
    cout << get<4>(tp) << endl;

    //Transform(MakeIndexes<tuple_size<Tuple>::value>::type(), tp);
    IndexTp<1, 2, 3, 4> itp;
    //Transform2(itp, tp);
    Transform2(tp, 1, 2, 3, 4, 5);

    //cout << "------------" << endl;
    //cout << tuple_size<Tuple>::value << endl;

    //auto it = get(tp);
    //
    //cout << tp_elem << endl;


    return 0;
}